package cn.lili.modules.payment.entity.dto;

import cn.hutool.core.text.CharSequenceUtil;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.exception.ServiceException;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * 支付子参数
 *
 * @author Chopper
 * @since 2020/12/19 11:46
 */
@Data
@ToString
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PayParamItem implements Serializable {


    @NotNull
    @ApiModelProperty(value = "支付单号")
    private String sn;

    @ApiModelProperty(value = "收款人：可以是店铺id、供应商id、分销商id等")
    private String payeeId;

    @ApiModelProperty(value = "描述")
    private String description;

    @ApiModelProperty(value = "订单金额")
    private Double price;


    @ApiModelProperty(value = "是否为特殊订单：特殊订单为某一端结算金额为负数，那么付款目标转向平台子商户，然后分账统一从平台余额中提取")
    private Boolean specialOrder;

    @ApiModelProperty(value = "商户id:第三方支付发起交易号: 调用方无需传递，支付业务会进行填充")
    private String mchId;

    @ApiModelProperty(value = "第三方支付发起交易号: 调用方无需传递，支付业务会进行填充")
    private String outTradeNo;


    public String getSn() {
        if (CharSequenceUtil.isEmpty(sn)) {
            throw new ServiceException(ResultCode.PARAMS_ERROR, "订单号不能为空");
        }
        return sn;
    }


    public Double getPrice() {
        if (price == null || price < 0) {
            throw new ServiceException(ResultCode.PARAMS_ERROR, "金额异常");
        }
        return price;
    }
}
